﻿namespace Example.Cryptography
{
    using System;
    using System.Diagnostics.CodeAnalysis;

    [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Ciphertext", Justification = "The casing is correct.")]
    public sealed class TripleDesCiphertext
    {
        private byte[] _ciphertext;

        [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "ciphertext", Justification = "The casing is correct.")]
        public TripleDesCiphertext(string ciphertext)
            : this(Convert.FromBase64String(ciphertext))
        {
        }

        [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "ciphertext", Justification = "The casing is correct.")]
        public TripleDesCiphertext(byte[] ciphertext)
        {
            Ciphertext = ciphertext;
        }

        private byte[] Ciphertext
        {
            get
            {
                return _ciphertext;
            }

            set
            {
                if (null == value)
                {
                    throw new ArgumentNullException("value");
                }

                _ciphertext = value;
            }
        }

        public byte[] ToBytes()
        {
            return Ciphertext;
        }

        public override string ToString()
        {
            return Convert.ToBase64String(Ciphertext, Base64FormattingOptions.None);
        }
    }
}